import json


# 读取配置文件
def read_json_file(file_path):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            json_data = json.load(file)
        return json_data
    except FileNotFoundError:
        print(f"文件 '{file_path}' 未找到.")
    except IOError as e:
        print(f"读取文件 '{file_path}' 发生错误: {e}")
    except json.JSONDecodeError as e:
        print(f"JSON 解析错误: {e}")
    except Exception as e:
        print(f"发生异常: {e}")


# 写入配置文件
def write_config(file_path, config):
    with open(file_path, 'w') as file:
        json.dump(config, file, indent=4)


def read_file_contents(file_path):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            contents = file.read()
        return contents
    except FileNotFoundError:
        print(f"文件 '{file_path}' 未找到.")
    except IOError as e:
        print(f"读取文件 '{file_path}' 发生错误: {e}")
    except Exception as e:
        print(f"发生异常: {e}")


def write_to_txt(text, file_path):
    with open(file_path, 'w',encoding='utf-8') as file:
        file.write(text)


"""
    读取配置文件 返回list
"""


def get_web_table():
    data = read_json_file('../resources/conf_xpath.json')
    conf_list = data.get('web_table')
    return conf_list
